package materials.matrix;

import java.io.Serializable;

public class MatrixMaterial implements MatrixMaterialInterface, Serializable {

	/**
	 * Konstruktor für eine Neue Matrix
	 * 
	 * @param real_m
	 *            - Höhe der AMtrix
	 * @param _n
	 *            - Bretie der MAtrix
	 */
	public MatrixMaterial(int m, int n) {
		real_m = m;
		real_n = n;
		_matrix = new double[m][n];
		initMatrix();
	}

	private void initMatrix() {
		for (int n = 0; n < real_n; n++) {
			for (int m = 0; m < real_m; m++) {
				_matrix[m][n] = 0;
			}
		}
	}

	private int real_m;
	private int real_n;

	private double[][] _matrix;

	@Override
	public double[] getColumn(int n) {
		double[] spalte = new double[real_m];
		for (int i = 0; i < real_m; i++) {
			spalte[i] = _matrix[i][n];
		}
		return spalte;
	}

	@Override
	public double[] getRow(int m) {
		double[] row = new double[real_n];
		for (int i = 0; i < real_n; i++) {
			row[i] = _matrix[m][i];
		}
		return row;
	}

	public int getM() {
		return real_m;
	}

	public int getN() {
		return real_n;
	}

	@Override
	public int getSize() {
		return real_m * real_n;
	}

	@Override
	public double getValue(int m, int n) {
		assert m >= 1;
		assert n >= 1;
		return _matrix[m - 1][n - 1];
	}

	@Override
	public void setValue(int m, int n, double value) {
		assert m >= 1;
		assert n >= 1;
		if (Math.abs(value) > 20) {
			value = Math.signum(value)*20;
		}
		_matrix[m - 1][n - 1] = value;
	}

	public double[][] getMatrix() {
		return _matrix;
	}

	public void printMatrix() {
		for (int i = 0; i < real_m; i++) {
			for (int j = 0; j < real_n; j++) {
				System.out.print(_matrix[i][j] + "\t");
			}
			System.out.print("\n");
		}
	}
}
